package com.xxl.job.admin.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xxl.job.admin.core.model.XinApi;
import com.xxl.job.admin.dao.XinApiDao;
import com.xxl.job.admin.service.XinApiService;

/**
 * @createat 2017-06-08
 * @author zhouzhe
 *
 */
@Service
public class XinApiServiceImpl implements XinApiService {
	
	public String _error = new String();
	
	@Resource
	private XinApiDao xinApiDao;
	
	@Override
	public String getError()
	{
		return this._error;
	}
	
	@Override
	public boolean addApi(XinApi xinapi)
	{
		if(!this.isTypeUsed(xinapi.getType()))
		{
			this._error = "api名称已近使用过了";
			return false;
		}
		return xinApiDao.save(xinapi);
	}
	
	@Override
	public boolean deleteApi(int id)
	{
		if(xinApiDao.remove(id)) return true;
		else return false;
	}
	
	@Override
	public boolean deleteApi(XinApi xinapi)
	{
		return true;
	}
	
	@Override
	public Map<String, Object>getApiList(int start)
	{
		int num = 10; // 每页显示的数量
		Map<String, Object>map = new HashMap<>();
		map.put("data", xinApiDao.findAll(start, num));
		map.put("length", xinApiDao.countPages(num));
		return map;
	}
	
	private boolean isTypeUsed(String type)
	{
		return false;
	}
	
}
